package com.it.rabbitmqwithjiang.Service.Impl;


import com.it.rabbitmqwithjiang.Dao.MessageDao;
import com.it.rabbitmqwithjiang.Service.Publisher;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional
@Service("publisher")
public class PublisherImpl implements Publisher {
	@Resource
	RabbitTemplate rabbitTemplate;

	@Transactional
	public void senddefaultdirectMessage(String queue, MessageDao messageDao) {
		rabbitTemplate.convertAndSend(queue, messageDao);
	}

	public void senddirectMessage(MessageDao messageDao, String routingkey) {
		rabbitTemplate.convertAndSend("direct", routingkey, messageDao);
	}
	public void sendfanoutMessage(MessageDao messageDao) {
		rabbitTemplate.convertAndSend("fanout", "", messageDao);    //广播没有routingKey
	}
	public void sendtopicMessage(MessageDao messageDao, String routingkey) {
		rabbitTemplate.convertAndSend("topic", routingkey, messageDao);
	}

	@Override
	public void TTLMessage(Message message) {
		rabbitTemplate.convertAndSend("TtlDirect", "TTL", message);
	}


}
